package com.huobao.yunying.adapters;

import java.util.Map;

import org.simple.eventbus.EventBus;

import com.huobao.yunying.activitys.muyingquan.SheQuTieZi;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;
import com.huobao.zhangying.R;
import com.xrz.sxm.base.dialog.BaseDialog;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

import joanzapata.android.BaseAdapterHelper;
import joanzapata.android.QuickAdapter;

public class Adapter_Shequ_MyFaTie extends QuickAdapter<SheQuTieZi> {

	public Adapter_Shequ_MyFaTie(Context context) {
		super(context, R.layout.item_shequ_myfatie);
	}

	@Override
	protected void convert(BaseAdapterHelper arg0, final SheQuTieZi arg1) {
		TextView tv_jing = arg0.getView(R.id.tv_shequmyfatie_jing);
		TextView tv_re = arg0.getView(R.id.tv_shequmyfatie_re);
		TextView tv_ding = arg0.getView(R.id.tv_shequmyfatie_ding);
		TextView tv_title = arg0.getView(R.id.tv_shequmyfatie_title);
		TextView tv_content = arg0.getView(R.id.tv_shequmyfatie_content);
		TextView tv_createtime = arg0.getView(R.id.tv_shequmyfatie_time);
		TextView tv_num = arg0.getView(R.id.tv_shequmyfatie_num);
		TextView tv_quanzi = arg0.getView(R.id.tv_shequmyfatie_quanzi);
		TextView btn_del = arg0.getView(R.id.btn_shequmyfatie_del);
		tv_jing.setVisibility(arg1.getIsbetter().equals("1") ? View.VISIBLE : View.GONE);
		tv_re.setVisibility(arg1.getIshot().equals("1") ? View.VISIBLE : View.GONE);
		tv_ding.setVisibility(arg1.getIsfirst().equals("1") ? View.VISIBLE : View.GONE);
		tv_title.setText(arg1.getTitle());
		tv_content.setText(arg1.getContent());
		tv_createtime.setText(arg1.getCreate_time());
		tv_num.setText(arg1.getComments());
		tv_quanzi.setText(arg1.getGname());
		btn_del.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				BaseDialog.TBox("确定删除吗？", context, new BaseDialog.OnDialogSelectListener() {
					@Override
					public void onSelect(String input) {
						if (input.equals("true"))
							del(arg1);
					}
				});
			}
		});

	}

	protected void del(final SheQuTieZi arg1) {
		Map<String, String> map = HttpUtil.getParams("app", "posttopic", "act", "drop", "id", arg1.getPid());
		Http.getInstant().sendRequest(context, map, new HttpListener() {

			@Override
			public void onHttpSuccess(String result) {
				EventBus.getDefault().post("", "refresh");
				Toast.makeText(context, "删除成功！", Toast.LENGTH_SHORT).show();
				remove(arg1);
				notifyDataSetChanged();
			}

			@Override
			public void onHttpError(String error) {
				// TODO Auto-generated method stub

			}
		});
	}

}
